package hsh.gui;

import hsh.command.Command;
import hsh.command.WashClothesCommand;
import hsh.kernel.OperatingSystemKernel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Hashtable;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Shell {

	/*
	private JPanel mainPane;
	private JTextArea textArea;
	private JLabel house;
	private JLabel device;
	private String standadText = "HSH OS:> ";
	final static boolean MULTICOLORED = false;
	private Hashtable<String, Command> commands;

	    //Specify the look and feel to use.  Valid values:
	    //null (use the default), "Metal", "System", "Motif", "GTK+"
	final static String LOOKANDFEEL = null;

	    
	public Shell(OperatingSystemKernel kernel) {
		 mainPane = new JPanel();
		 this.textArea = new JTextArea();
		 
		 this.commands = new Hashtable<String, Command>();
		this.commands.put("washcl", new WashClothesCommand(kernel.getScheduler()));
			
		 
		// textArea.setSize(500, 200);
		 textArea.setPreferredSize(new Dimension(500,100));
		 textArea.setBackground(Color.BLACK);
		 textArea.setForeground(Color.GREEN);
		 
		 
		 house = new JLabel(new ImageIcon("house2.jpg"));
		 device = new JLabel(new ImageIcon("lavar.jpg"));
		 
		
		 Font boldFont = new Font("Serif", Font.BOLD, 15);
		 textArea.setFont(boldFont);
		 textArea.setText(standadText);
		 
		 textArea.addKeyListener( new KeyAdapter(){

			@Override
			public void keyPressed(KeyEvent e) {
			
				
				if(textArea.getText().length() <= standadText.length()){
					textArea.setText(standadText);
				}
		
			
				if(e.getKeyChar() == '\n'){
					
					String command = textArea.getText();
					commands.get("washcl").execute();
				}
			}
			
				
			
			

		});
		 
		 
		 mainPane.setPreferredSize(new Dimension(500,500));
		 
		 
		 mainPane.setLayout(new BorderLayout());
		 mainPane.add(textArea,BorderLayout.SOUTH);
		 mainPane.add(house,BorderLayout.WEST);
		 mainPane.add(device,BorderLayout.EAST);
		 //mainPane.setSize(500, 800);
		
		 
		 //mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.PAGE_AXIS));
	
		 
		 
	        if (MULTICOLORED) {
	            mainPane.setOpaque(true);
	            mainPane.setBackground(new Color(255, 0, 0));
	        }
	     //mainPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
	    // mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
	    // mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
	     //mainPane.add(Box.createGlue());
	     

	}
	
	private static void initLookAndFeel() {
		String lookAndFeel = null;

        if (LOOKANDFEEL != null) {
            if (LOOKANDFEEL.equals("Metal")) {
                lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
            } else if (LOOKANDFEEL.equals("System")) {
                lookAndFeel = UIManager.getSystemLookAndFeelClassName();
            } else if (LOOKANDFEEL.equals("Motif")) {
                lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
            } else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
                lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
            } else {
                System.err.println("Unexpected value of LOOKANDFEEL specified: "
                                   + LOOKANDFEEL);
                lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
            }

            try {
                UIManager.setLookAndFeel(lookAndFeel);
            } catch (ClassNotFoundException e) {
                System.err.println("Couldn't find class for specified look and feel:"
                                   + lookAndFeel);
                System.err.println("Did you include the L&F library in the class path?");
                System.err.println("Using the default look and feel.");
            } catch (UnsupportedLookAndFeelException e) {
                System.err.println("Can't use the specified look and feel ("
                                   + lookAndFeel
                                   + ") on this platform.");
                System.err.println("Using the default look and feel.");
            } catch (Exception e) {
                System.err.println("Couldn't get specified look and feel ("
                                   + lookAndFeel
                                   + "), for some reason.");
                System.err.println("Using the default look and feel.");
                e.printStackTrace();
            }
        }

		
	}
	
	public static  Shell  createAndShowGui(OperatingSystemKernel kernel){
		initLookAndFeel();
		JFrame frame = new JFrame("Console HSW OS");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		Shell shell = new Shell(kernel);
		shell.mainPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(shell.mainPane);
       // frame.setSize(500, 800);
        frame.setPreferredSize(new Dimension(600,550));
        //Display the window.
        frame.pack();
        frame.setVisible(true);
        
        return shell;
	}
	
	

	public static void run(OperatingSystemKernel kernel) {
		SwingUtilities.invokeLater(new Runnable(){
			public void run() {
				createAndShowGui(kernel);
			}});
	}*/
}
